package com.kedacom.demo.modb.weibo.service;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kedacom.demo.modb.weibo.dao.TsoAccountDao;
import com.kedacom.demo.modb.weibo.model.Account;

/**
 * 用户帐号管理实现
 * @author luocanfeng
 * @date 2013-1-14
 */
@Transactional
@Service("accountService")
public class AccountServiceImpl implements AccountService {

	private Logger logger = LoggerFactory.getLogger(getClass());

	@Resource(name = "apJdbcDaoSupport")
	private JdbcDaoSupport apJdbcDaoSupport;

	@Resource
	private TsoAccountDao tsoAccountDao;

	@Override
	public List<Account> listAll() {
		return tsoAccountDao.listAll();
	}

	private String modifyBriefSql = "update account set brief=? where moid=?";

	@Override
	public void modifyBrief(String moid, String brief) {
		// persist to db
		apJdbcDaoSupport.getJdbcTemplate().update(modifyBriefSql, brief, moid);
		logger.debug("Persisted to apdb.");
		tsoAccountDao.modifyBrief(moid, brief);
		logger.debug("Persisted to tsodb.");
	}

	@Override
	public Account getByMoid(String moid) {
		return tsoAccountDao.getByMoid(moid);
	}

}
